#include <iostream>
#include <deque>

#include "eval_thresh.h"
#include "Image.H"
#include "Util.H"
#include "IO.H"
#include "rgm.h"

using namespace std;
using namespace pip;

int main(int argc, char *argv[])
{
  if (argc < 8) {    //get commandline arguments
	  error("", "Usage: hys-threshold -i <input image> -connectivity <{4,6,8,18,26}> -tH <high threshold> -tL <low threshold>\n");
  }
  vector<string> args(argv, argv + argc);


  Image<float> in_float;     // reserve some variables
  Image<short> in_short;
  Image<unsigned char> in_char;
  Image<Color<unsigned char> > in_color;
  Image<unsigned char> out;

  string inputname;
  int n(0);
  float tHigh(0),tLow(0);

  getScalarArg(args, "-i", inputname);   // init input
  getScalarArg(args, "-connectivity", n);
  getScalarArg(args, "-tH", tHigh);
  getScalarArg(args, "-tL", tLow);

  if (importFile(in_float, inputname))  //try correct image format
  {
     hysteresisThresholding(in_float, out, n, float(tHigh), float(tLow));
  } else if (importFile(in_short, inputname)) 
  {
     hysteresisThresholding(in_short, out, n, short(tHigh), short(tLow));
  } else if (importFile(in_char, inputname)) 
  {
	 hysteresisThresholding(in_char, out, n, unsigned char(tHigh), unsigned char(tLow));
  } else if (importFile(in_color, inputname)) 
  {                            
	hysteresisThresholding(in_color, out, n, Color<unsigned char>(tHigh), Color<unsigned char>(tLow));
  } else 
  {   
	  cout << "The inputimage is not an Image of pixeltype: [unsigned char(also colored), short or float] !\n";
      //return 4;
  }
  
  cout << "Operation done\n";  

  if (!exportFile(out, "output_hysteresis.pip"))  //save result
	  cout << "unable to write output file onto disk...\n";
system("pause");
// do validate the accurany and ASD i used the solution code from last assignment and a nested for loop over the thresholds...



}